import { observable, action } from 'mobx'
import axios from 'axios'
import notificationWithIcon from "../../../common/notificationWithIcon";
import modalDisplay from "../../../common/informModal";

class BaseInfoStore {
    @observable baseInfo={}
    @observable status=""
    actions = {
        getBaseInfo:action(()=>{
            axios.get('/api/user/base/info')
                .then((response)=> {
                    console.log(response)
                    if(response.data.status.code===1){
                        this.baseInfo=response.data.result
                        this.status="0"
                    }
                })
                .catch(function (error) {
                    console.log(error);
                });
        }),
        launchBaseInfo: action((baseInfo,toggle)=>{
            baseInfo.licensePath=this.baseInfo.licensePath
            baseInfo.phoneNo=this.baseInfo.phoneNo
            baseInfo.headimg=this.baseInfo.headimg
            axios.post('/api/user/base/update',baseInfo)
                .then((response)=> {
                    if(response.data.status.code===1){
                        toggle(false)
                        modalDisplay('success','成功',"用户信息保存成功",null)
                        this.status="2"
                        this.actions.getBaseInfo()
                    }
                    else{
                        toggle(false)
                        modalDisplay('error',response.data.status.message,"",null)
                    }
                })
                .catch(function (error) {
                    toggle(false)
                    modalDisplay('error','保存失败',error.response,null)
                    console.log(error);
                });
        })
    }
}
export default new BaseInfoStore()